﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data.SqlClient;
using System.Configuration;

namespace CarServiseSite
{
    public partial class WorkersSum_Manager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string type = null;
            if (Session["Type"] != null)
                type = Session["Type"].ToString();

            //insert back menu
            if (type == "Manager")
            {
            }
            else
            {
                Page.Visible = false;
                Response.Redirect("~/404.aspx");
            }
        }

        protected void ButtonExit_Click(object sender, EventArgs e)
        {
            string type = null;
            if (Session["Type"] != null)
                type = Session["Type"].ToString();

            string login = null;
            if (Session["Login"] != null)
                login = Session["Login"].ToString();


            if (login == null || type == null)
            {
            }
            else
            {
                string setQuckieProc = "";

                if (type == "Admin")
                    setQuckieProc = "SetUidAdminByLogin";
                else if (type == "Manager")
                    setQuckieProc = "SetUidManagerByLogin";
                else if (type == "Worker")
                    setQuckieProc = "SetUidWorkerByLogin";
                else if (type == "Client")
                    setQuckieProc = "SetUidClientByLogin";

                Random rand = new Random();
                int UIDint = rand.Next(0, 1000000000);

                ConnectionStringSettings css =
                    ConfigurationManager.ConnectionStrings["CarServiceConnectionString"];
                string ss = css.ConnectionString;

                //write database
                SqlConnection conn = new SqlConnection(ss);
                conn.Open();
                SqlCommand cmd = new SqlCommand(setQuckieProc, conn);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@Login", login);
                cmd.Parameters.AddWithValue("@UID", UIDint.ToString());
                cmd.ExecuteNonQuery();

                conn.Close();

                Session.Remove("Login");
                Session.Remove("Type");

                Response.Redirect("~/default.aspx");
            }
        }
    }
}